
import Vuex from 'vuex'
import Vue from 'vue'
import { Toast } from 'vant';

var _this = this;
const module = {
    state: {
        user: {
            name: 'rookie'
        },
         loadingCount: 0,
         title:'AIR TECH',
         loadinToast:null,
    },
    getters: {},
    mutations: {
        setUser(state, payload) {
            if (payload.hasOwnProperty('name')) {
                state.user.name = payload.name
            }
        },showLoading(){
            
            if( store.state.loadingCount<=0){
                store.state.loadinToast =  Toast.loading({
                    duration: 0,       // 持续展示 toast
                    forbidClick: true, // 禁用背景点击
                    loadingType: 'spinner'
                  });
            }
            store.state.loadingCount++;
          },
          hideLoading(){
            store.state.loadingCount--;
            if(  store.state.loadingCount<=0){
                store.state.loadinToast.clear();
            }
          },setTitle(state,obj){
              if(obj.name){
                  store.state.title=obj.name;
              }
          }
    },

}
Vue.use(Vuex);
const store = new Vuex.Store(module);
export default store;
